package cn.tedu.bonfire.front.payment.dao.persist.repository.impl;

import cn.tedu.bonfire.front.payment.dao.persist.mapper.OrderMapper;
import cn.tedu.bonfire.front.payment.dao.persist.repository.IOrderRepository;
import cn.tedu.bonfire.front.payment.pojo.entity.Order;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class OrderRepositoryImpl implements IOrderRepository {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void insert(Order order) {
        orderMapper.insert(order);
    }

    @Override
    public void updateOrderStatus(Order order) {
        orderMapper.updateOrderStatusById(order);
    }

    /*@Override
    public void updateHabitatCoin (Long authorId, Double totalPrice) {
        orderMapper.updateHabitatCoin(authorId,totalPrice);
    }*/

    @Override
    public Long countByOutTradeNo(String outTradeNo) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_no", outTradeNo);
        return orderMapper.selectCount(queryWrapper);
    }

    @Override
    public Order getOrderDetailByOrderTradeNo(String outTradeNo) {
        return orderMapper.getOrderDetailByOrderTradeNo(outTradeNo);
    }

    @Override
    public Order getByTradeNo(String outTradeNo) {
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("order_no",outTradeNo);
        Order order = orderMapper.selectOne(queryWrapper);
        return order;
    }

    /*@Override
    public Double getOrderSum(Long userId) {
        return orderMapper.getOrderSum(userId);
    }*/
}
